/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Jan 27, 2010 12:40:15 AM $
 *
 * Author: Eric Yang
 * Date  : Jan 27, 2010 12:40:15 AM
 *
 */
package com.gooex.web.action.gbuy.order;

import java.util.ArrayList;
import java.util.List;
import org.c4j.system.web.action.Protected;
import org.c4j.system.web.exception.ServiceException;

import com.gooex.domain.base.Category;
import com.gooex.domain.base.Order;
import com.gooex.domain.base.Product;
import com.gooex.service.base.IProductManager;
import com.gooex.service.base.exception.ExceptionCode;

/**
 * @author Eric Yang
 * @version 1.0
 */
public class SelectProductAction extends BaseOrderAction implements Protected {

	private IProductManager productManager;

	private String productId;

	private String orderId;

	private String keyword;

	private Order order;

	private Product product;

	private List<Product> products;

	public String selectProduct() throws Exception {
		order = orderManager.getOrder(orderId);
		if (order == null)
			throw new ServiceException(ExceptionCode.SYSTEM_ACCESS_ERROR, "");

		Category category = order.getCategory();
		products = productManager.getProducts(category, keyword, page);
		if (products == null)
			products = new ArrayList<Product>();
		List<Product> userProducts = productManager.getProducts(category, getCurrentUser(), true);
		if (userProducts != null)
			products.addAll(userProducts);

		return SUCCESS;
	}

	public List<Product> getProducts() {
		return products;
	}

	public String getProductId() {
		return productId;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public void setProductManager(IProductManager productManager) {
		this.productManager = productManager;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}
}
